package com.cdivtc.management;

import com.DruidConfig;
import com.cdivtc.management.utils.IdWorker;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import tk.mybatis.spring.annotation.MapperScan;

import javax.servlet.MultipartConfigElement;


@SpringBootApplication
@Configuration
@MapperScan(basePackages = {"com.cdivtc.management.dao"})
public class Application  extends SpringBootServletInitializer {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
@Bean
	public IdWorker idWorker(){
		return  new IdWorker();
}
	@Bean
	public MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		//  单个数据大小
		factory.setMaxFileSize("500048KB"); // KB,MB
		/// 总上传数据大小
		factory.setMaxRequestSize("5002400KB");
		return factory.createMultipartConfig();
	}
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {

		return builder.sources(this.getClass());
	}

	@Bean("transactionManager")
	public DataSourceTransactionManager transactionManager(){
		return new DataSourceTransactionManager(new DruidConfig().dataSource());
	}

}
